<?php
/*
 * @component AlphaGetCouponCode
 * @copyright Copyright (C) 2008-2009 Bernard Gilly
 * @license : GNU/GPL
 * @Website : http://www.alphaplug.com
 */

defined('_JEXEC') or die('Restricted access');
global $mainframe;

$installfinish =  "Installation finished";
$color = "green";

// publish plugin rule
$db	=& JFactory::getDBO();

$query = "INSERT INTO #__alpha_userpoints_rules (`id`, `rule_name`, `rule_description`, `rule_plugin`, `plugin_function`, `access`, `component`, `calltask`, `taskid`, `points`, `percentage`, `rule_expire`, `sections`, `categories`, `content_items`, `exclude_items`, `published`, `system`, `duplicate`, `blockcopy`, `autoapproved`, `fixedpoints`, `category`) VALUES
('', 'Get coupon code', 'Allow users to convert their points into coupon code with VirtueMart', 'VirtueMart', 'plgaup_alphagetcouponcode_vm', '1', '', '', '', 0, 0, '0000-00-00 00:00:00', '', '', '', '', 0, 0, 0, 0, 1, 0, 'cd');";
$db->setQuery( $query );

if ( !$db->query() ) {
	$installfinish =  "Installation corrupted !";
	$color = "red";
	$error = JText::_('AlphaGetCouponCode is not successfully installed. You must unsinstall AlphaGetCouponCode and install AlphaUserPoints component in first.');
	JError::raiseNotice(0, $error );
	return false;
}

// Modify the admin icons
$query = "SELECT id FROM #__components WHERE `name`='AlphaGetCouponCode'";
$db->setQuery( $query );
$id = $db->loadResult();

//add new admin menu images
$query = "UPDATE #__components SET `name`='AlphaGetCouponCode', admin_menu_img = '../administrator/components/com_alphagetcouponcode/assets/images/agcc_icon.png' WHERE id='$id'";
$db->setQuery( $query );
$db->query();
?>
<table width="100%" border="0">
<tr>
	<td><h1>AlphaGetCouponCode installed !</h1>
	<p>Official website: <a href="http://www.alphaplug.com" target="_blank">http://www.alphaplug.com</a><br />
	  Author: Bernard Gilly<br>
	  Copyright: AlphaGetCouponCode &copy; 2008-2009 - <a href="http://www.alphaplug.com" target="_blank">www.alphaplug.com</a><br />
	  <br />
	</p>
	</td>
</tr>
<tr>
  <td style="border:1px solid #999999;color:<?php echo $color; ?>;font-weight:bold; background-color:E0E0E0;"><?php echo $installfinish; ?></td>
</tr>
</table>
